<template>
  <div class="baseConfig">
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="small" inline style="text-align: right">
        <el-form-item label="名称">
          <el-input v-model="param.name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="loadBaseConfigs" icon="el-icon-search">搜索</el-button>
        </el-form-item>
        <el-button type="primary" size="small" @click="toAddHandler">下一页</el-button>
      </el-form>
      <div style="text-align: left">
      <el-button type="primary" size="small" @click="toAddHandler">新增</el-button>
      <el-button type="success" size="small" @click="downloadHandler">导出</el-button>
      </div>
    </div>
    <!-- /按钮 -->
    <!-- {{baseConfigs}} -->
    <!-- 表格 -->
    <el-table size="small" :data="baseConfigs">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column
        label="名称"
        prop="name"
        align="center"
      ></el-table-column>
      <el-table-column label="val" prop="val" align="center"></el-table-column>
      <el-table-column
        label="简介"
        prop="introduce"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" width="200px" align="center">
        <!-- 定制-插槽 -->
        <template slot-scope="scope">
          <el-button
            type="primary"
            circle
            icon="el-icon-edit"
            size="mini"
            @click="editHandler(scope.row)"
            >修改</el-button
          >
          <el-button
            type="danger"
            circle
            icon="el-icon-delete"
            size="mini"
            @click="deleteHandler(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>
<script>
import { del, get, post } from "@/utils/request";
export default {
  // 页面数据
  data() {
    return {
      //参数，用于保存检索的参数
      param: {
        name:""
      },
      //组件模块中需要的数据
      baseConfigs: [],
    };
  },
  // 页面渲染的时候会调用的函数
  created() {
    this.loadBaseConfigs();
  },
  // 所有的方法
  methods: {
    downloadHandler(){
       window.location.href = "http://47.111.2.173:8888/baseConfig/download?name="+this.param.name;
    },
    //修改函数
    editHandler(row) {
      this.$router.push({
        path: "/baseConfig/create",
        query: row,
      });
    },
    //删除
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://47.111.2.173:8888/baseConfig/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadBaseConfigs();
        });
      });
    },
    //跳转
    toAddHandler() {
      this.$router.push("/baseConfig/create");
    },
    //查询后台中的应用信息
    loadBaseConfigs() {
      let url = "http://47.111.2.173:8888/baseConfig/query";
      get(url, this.param).then((resp) => {
        this.baseConfigs = resp.data;
      });
    },
  },
};
</script>

<style scoped>
.btns {
  margin-bottom: 0.5em;
}
</style>